<?php
/**
 * Created by PhpStorm.
 * User: liuxin
 * Date: 2018/1/12
 * Time: 下午2:14
 */

namespace common\components;

class RedisCommon
{
    public static $_instance;

    private function __construct()
    {
        # code...
    }
    private function __clone()
    {
        # empty
    }
    public static function Instance()
    {
        if(!(self::$_instance instanceof self))
        {
            self::$_instance = new self();
        }
        return self::$_instance;
    }

    public static function getTelephoneVerifyCode($user_tel, $act)
    {
        $key = $user_tel . '_' . $act ;
        $ret = Factory::Redis()->get($key);
        return $ret;
    }
    public function delTelephoneVerifyCode($user_tel, $act){
        $key = $user_tel . '_' . $act ;
        Factory::Redis()->del($key);
    }

    /**
     * 设置手机操作权限
     *
     * @param string $user_tel
     * @param string $act
     * @param string $value
     * @param string $platform_id
     * @return bool
     */
    public function setTelephonePower($user_tel, $act, $value)
    {
        $key = $user_tel . '_p_' . $act;
        return Factory::Redis()->setex($key, TEL_RESET_EXPIRE_TIME, $value);
    }


    /**
     * 保存发送的手机验证码到redis中
     * @param string $user_tel
     * @param string $code
     * @return
     */
    public function saveTelephoneVerifyCode($user_tel, $code, $act)
    {
        $key = $user_tel . '_' . $act;
        return Factory::Redis()->setex($key, TEL_CODE_EXPIRE_TIME, $code);
    }
}